#!/usr/bin/env python
# -*- coding: utf-8 -*-


import itchat, time
from itchat.content import *

sendToName=u'Garr'
SendList=[]
itchat.auto_login()
friendList = itchat.get_friends(update=True)[1:] 
for i in range(len(friendList)):
    #获得微信用户的“备注”or“昵称”
    weChat_Name=friendList[i]['RemarkName'] or friendList[i]['NickName']
    if (weChat_Name.find(sendToName)!=-1):
        SendList.append(friendList[i]['UserName'])
        a=friendList[i]
        remarkName=weChat_Name
if len(SendList)>1:
    print u'太多匹配人物了'

    

global getreturnShabi
getreturnShabi=[u'裕',u'导',u'滨',u'你妈',u'你妹']
global sendreturnShabi
sendreturnShabi=[u'领养',u'汪汪',u'爸爸好',u'爷爷好',u'妈妈好']




myName=itchat.search_friends(name=u'侠盗单车')
robotName=itchat.search_mps(name=u'小冰')
global FromUserName 
FromUserName=a['UserName']




@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
def text_reply_group(msg):
    if msg['FromUserName']==a['UserName']:
        for i in getreturnShabi:
            if msg['Text'].find(i)!=-1:
                itchat.send('%s,你好棒' %  remarkName, FromUserName)
        if msg['FromUserName']!=myName[0]['UserName']:
            itchat.send_msg(msg=msg['Text'], toUserName=robotName[0]['UserName'])
                
        
@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING],isMpChat=True)
def text_replyTo(msg):
    if msg['FromUserName']==robotName[0]['UserName']:
        reply=msg['Text']
        for i in sendreturnShabi:
            if  (msg['Text'].find(i)!=-1):
                reply=actralName+u',你好棒'
        reply=reply.replace(u'小冰',u'你滨哥我')
        reply=reply.replace(u'人家',u'你大爷我')
        reply=reply.replace(u'耶～',u'')
        reply=reply.replace(u'～',u'')
        itchat.send('%s' %  reply, FromUserName)

@itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO, SYSTEM, VOICE])
def download_files(msg):
    if msg['FromUserName']==a['UserName']:
        msg['Text'](msg['FileName'])
        msgFrom='@%s@%s' % ({'Picture': 'img', 'Video': 'vid'}.get(msg['Type'], 'fil'), msg['FileName'])
        itchat.send(msgFrom,toUserName=robotName[0]['UserName'])

@itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO, SYSTEM, VOICE],isMpChat=True)
def send_files(msg):
    if msg['FromUserName']==robotName[0]['UserName']:
        msg['Text'](msg['FileName'])
        msgFrom='@%s@%s' % ({'Picture': 'img', 'Video': 'vid'}.get(msg['Type'], 'fil'), msg['FileName'])
        itchat.send(msgFrom,toUserName=FromUserName)


itchat.run()
